<?php
 class News extends CI_Model{
    
    function __construct(){
        parent::__construct();
    }
    
    /**
     * Get list product index
     * @author tien.nguyen
     * @return array
     */
    public function getListIndex(){
       $this->db->where('Visible', 1);
       $this->db->limit(6);
       $this->db->order_by('CreatedDate', 'DESC');
       $this->db->join('news_categories', 'news_categories.NewsCategoryId = news.CategoryId');
       $this->db->where('news_categories.NewsCategoryCode = "news"');
       $query = $this->db->get('news');
        
       return $query->result_array(); 
    }
    
    /**
     * Get list news 
     * @author tien.nguyen
     */
    public function getListNews($cate, $page = 1){
       $this->db->where('Visible', 1);
       $this->db->limit(10, ($page - 1) * 10);
       $this->db->order_by('CreatedDate', 'DESC');
       $this->db->join('news_categories', 'news_categories.NewsCategoryId = news.CategoryId');
       $this->db->where('news_categories.NewsCategoryCode = "'. $cate .'"');
       $query = $this->db->get('news');
        
       return $query->result_array();  
    }
    
    
    /**
     * Get news by new id 
     * @author tien.nguyen
     * @return array
     */
    public function getNews($newsId){
       $query = $this->db->get_where('news', array('NewsId' => $newsId)); 
       return $query->row_array(); 
    }
 }
?>